new Vue({
    el: "#app",
    data: {
        fullscreenLoading: false,
        screenLoading: false,
        dialogDeleteVisible: false,
        dialogNewVisible: false,
        dialogUpdateVisible: false,
        adCateData: [],
        newAdCate:{},
        updateAdCate:{},
        id: null,
    },
    mounted: function () {
        var _this = this;
        _this.loadAdCateList();
    },
    methods: {
        trim: function (str) {
            if (isNaN(str)) {
                return str.replace(/(^\s*)|(\s*$)/g, "");
            } else {
                return str
            }
        },
        loadAdCateList: function () {
            var _this = this;
            axios.get(request_prefix + "/cash/adCate/list")
                .then(function (res) {
                    if (res.data.code === 0) {
                        _this.adCateData = res.data.data;
                    } else {
                        _this.$message.error(res.data.message);
                    }
                })
                .catch(function (res) {
                    _this.$message.error("请求过程发生错误");
                })
        },
        toNewDialog: function () {
            var _this = this;
            _this.updateAdCate = {};
            _this.dialogNewVisible = true;
        },
        confirmCreate: function () {
            var _this = this;
            if (_this.newAdCate.name == null || _this.newAdCate.name == '') {
                _this.$message.warning("广告类名不能为空");
                return;
            }
            axios.post(request_prefix + "/cash/adCate/add", _this.newAdCate)
                .then(function (res) {
                    if (res.data.code === 0) {
                        _this.loadAdCateList();
                        _this.dialogNewVisible = false;
                    } else {
                        _this.$message.error(res.data.message);
                        _this.dialogNewVisible = false;
                    }
                })
                .catch(function (res) {
                    _this.$message.error("请求过程中发生错误");
                })
        },
        toEditDialog: function (id) {
            var _this = this;
            axios.get(request_prefix + "/cash/adCate/detail", {
                params: {
                    id: id
                }
            })
                .then(function (res) {
                    if (res.data.code == 0) {
                        _this.updateAdCate = res.data.data;
                        _this.dialogUpdateVisible = true;
                    } else {
                        _this.$message.error(res.data.message);
                    }
                })
                .catch(function (res) {
                    _this.$message.error("请求过程发生错误");
                })
        },
        confirmUpdate: function () {
            var _this = this;
            if (_this.updateAdCate.name == null || _this.updateAdCate.name == '') {
                _this.$message.warning("广告类名不能为空");
                return;
            }
            axios.post(request_prefix + "/cash/adCate/update",_this.updateAdCate)
                .then(function (res) {
                    if (res.data.code === 0) {
                        _this.loadAdCateList();
                        _this.dialogUpdateVisible = false;
                    } else {
                        _this.$message.error(res.data.message);
                        _this.dialogUpdateVisible = false;
                    }
                })
                .catch(function (res) {
                    _this.$messgage.error("请求过程中发生错误");
                })
        },
        deleteRecommend: function (id) {
            var _this = this;
            _this.id = id;
            _this.dialogDeleteVisible = true;
        },
        confirmDelete: function () {
            var _this = this;
            var params = new URLSearchParams();
            params.append("id",_this.id);
            axios.post(request_prefix + "/cash/adCate/delete",params)
                .then(function (res) {
                    if(res.data.code === 0) {
                        _this.loadAdCateList();
                        _this.dialogDeleteVisible = false;
                    } else {
                        _this.$message.error(res.data.message);
                        _this.dialogDeleteVisible = false;
                    }
                })
                .catch(function (res) {
                    _this.$message.error("请求过程发生错误");
                })
        },
        backToAdList:function () {
            window.location.href = request_prefix + "/cash/ad/listPage";
        }
    }
});